package cn.com.zero.manager.auth.controller;

import cn.com.zero.api.log.annotation.Log;
import cn.com.zero.db.vo.PageVO;
import cn.com.zero.manager.auth.constant.LogType;
import cn.com.zero.manager.auth.po.ManagerPO;
import cn.com.zero.manager.auth.service.IManageLockedService;
import cn.com.zero.web.controller.BaseController;
import cn.com.zero.web.util.PageRequestUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author Huangyong
 * @version 1.0.0
 * @Description 被锁定管理员管理接口
 * @createTime 21/03/18 17:33:03
 */
@Api(tags = "被锁定管理员管理接口")
@Validated
@RestController
@RequestMapping("/manager/managerLocked")
public class ManageLockedController extends BaseController {

    /**
     * 被锁定管理员管理service
     */
    private IManageLockedService manageLockedService;

    @ApiOperation(value = "查询被锁定的管理员列表", notes = "当用户连续输入密码错误次数超过阈值时将被锁定")
    @GetMapping("/list")
    public PageVO<ManagerPO> queryList() {
        return PageRequestUtil.getPageInfo(()->manageLockedService.queryList());
    }

    @Log(content = "解锁管理员", logType = LogType.LOG_MANAGE)
    @ApiOperation(value = "解锁管理员")
    @ApiImplicitParam(paramType = "path", name = "userId", required = true, value = "用户ID")
    @DeleteMapping("/unlock/{userId}")
    public void unlockAdmin(@PathVariable("userId") String userId) {

        manageLockedService.unlockAdmin(userId);
    }

    @Autowired
    public void setManageLockedService(IManageLockedService manageLockedService) {
        this.manageLockedService = manageLockedService;
    }
}
